package com.mmall.Concurrency.example.ThreadPool;

import lombok.extern.log4j.Log4j;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

@Log4j
public class ThreadPoolExample4 {

    public static void main(String[] args) {
        ScheduledExecutorService service = Executors.newScheduledThreadPool(5);
        System.out.println("before");
//        service.schedule(new Runnable() {
//            @Override
//            public void run() {
//                System.out.println("线程执行");
//            }
//        },3, TimeUnit.SECONDS);
//
//        service.scheduleAtFixedRate(new Runnable() {
//            @Override
//            public void run() {
//                System.out.println("test");
//            }
//        },1,3,TimeUnit.SECONDS);  //延迟一秒，每隔三秒钟执行
//        service.shutdown();

        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("timer run");
            }
        },new Date(),5000);
    }
}
